<?php
class URLUltil {
	const ADMIN = 'Administrator';
	/**
	 * Enter description here .
	 * ..
	 * 
	 * @param HttpContext $context        	
	 */
	public static function adminPage($context) {
		return $context->getBaseUrl () . URLUltil::ADMIN;
	}
	/**
	 * Enter description here .
	 * ..
	 * 
	 * @param HttpContext $context        	
	 */
	public static function controllerHome($context, $controller) {
		return $context->getBaseUrl () . URLUltil::ADMIN . '/' . $controller . '/index/default.html';
	}
	/**
	 * Enter description here .
	 * ..
	 * 
	 * @param HttpContext $context        	
	 */
	public static function controllerList($context, $controller) {
		return $context->getBaseUrl () . URLUltil::ADMIN . '/' . $controller . '/list/default.html';
	}
	public static function controllerSearch($context, $controller) {
		if($controller == "UserSystem")
			return URLUltil::controllerList($context, $controller);
		return $context->getBaseUrl () . URLUltil::ADMIN . '/' . $controller . '/search/default.html';
	}
	public static function controllerCreate($context, $controller) {
		return $context->getBaseUrl (). URLUltil::ADMIN .  '/'.$controller.'/update/default.html';
	}
	/**
	 * Enter description here .
	 * ..
	 * 
	 * @param HttpContext $context        	
	 */
	public static function controllerEdit($context, $controller, array $id) {
		$first = true;
		$str = "";
		foreach ( $id as $key => $value ) {
			if ($first) {
				$str .= $controller . "_" . $key . "=" . $value;
				$first = false;
			} else
				$str .= "&" . $controller . "_" . $key . "=" . $value;
		}
		return $context->getBaseUrl () . URLUltil::ADMIN . '/' . $controller . '/edit/default.html';
	}
	/**
	 * @param HttpContext $context
	 * @param int $productId
	 * @return string
	 */
	public static function productDetails($context, $productId) {
		$product = ModelFactory::minstance("Product", Configuration::MODULE_DEFAULT);
		$urlInfo = $product->getDetailsForURL($productId);
		if($urlInfo != null)
			return $context->getBaseUrl () 
		. StringUltil::vnStrFilter($urlInfo[Product::CATNAME]) . '/'
		.StringUltil::vnStrFilter($urlInfo["name"]) .'-' . $productId.'.p.html';
		else 
			return "#";
	}
	public static function productDetails1($context, $id, $name, $catName) {
		if(isset($id) && isset($name) && isset($catName))
			return $context->getBaseUrl ()
			. StringUltil::vnStrFilter($catName) . '/'
					.StringUltil::vnStrFilter($name) .'-' . $id.'.p.html';
		else
			return "#";
	}
	public static function productCat($context, $id) {
		$product = ModelFactory::minstance("Product", Configuration::MODULE_DEFAULT);
		if(isset($id)){
			$name = $product->getProductCatName($id);
			return $context->getBaseUrl ()
			. StringUltil::vnStrFilter($name) .'-' . $id.'.c.html';
		}else
			return "#";
	}
	public static function productCatLi($context, $id) {
		$product = ModelFactory::minstance("Product", Configuration::MODULE_DEFAULT);
		if(isset($id)){
			$name = $product->getProductCatName($id);
			return '<li><a href="'.$context->getBaseUrl ()
			. StringUltil::vnStrFilter($name) .'-' . $id.'.c.html">'.$name.'</a></li>';
		}else
			return "";
	}
	public static function productCat1($context, $id, $name) {
		if(isset($id) && isset($name))
			return $context->getBaseUrl ()
			. StringUltil::vnStrFilter($name) .'-' . $id.'.c.html';
		else
			return "#";
	}
	public static function newsDetails1($context, $id, $name, $catName) {
		if(isset($id) && isset($name) && isset($catName))
			return $context->getBaseUrl ()
			. StringUltil::vnStrFilter($catName) . '/'
					.StringUltil::vnStrFilter($name) .'-' . $id.'.t.html';
		else
			return "#";
	}
	public static function productCatLink($context, $id) {
		return $context->getBaseUrl (). URLUltil::ADMIN .  '/ProductCat/update/default.html?id=' . $id;
	}
	public static function productLink($context, $productCatId) {
		return $context->getBaseUrl (). URLUltil::ADMIN .  '/Product/update/default.html?id=' . $productCatId;
	}
	public static function ProductTypeLink($context, $productCatId) {
		return $context->getBaseUrl (). URLUltil::ADMIN .  '/ProductType/update/default.html?id=' . $productCatId;
	}
	public static function productManufactureLink($context, $productCatId) {
		return $context->getBaseUrl (). URLUltil::ADMIN .  '/ProductManufacture/update/default.html?id=' . $productCatId;
	}
	public static function productDistributorLink($context, $productCatId) {
		return $context->getBaseUrl (). URLUltil::ADMIN .  '/ProductDistributor/update/default.html?id=' . $productCatId;
	}
	public static function ProductDisplayLink($context, $productCatId) {
		return $context->getBaseUrl (). URLUltil::ADMIN .  '/ProductDisplay/update/default.html?id=' . $productCatId;
	}
	public static function getImageUrl($context, $folder,$value){
		return $context->getBaseUrl() . 'public/media/images/'.$folder.'/'.$value;
	}
	public static function newsCatLink($context, $id) {
		return $context->getBaseUrl (). URLUltil::ADMIN .  '/NewsCat/update/default.html?id=' . $id;
	}
	public static function newsLink($context, $newsId) {
		return $context->getBaseUrl (). URLUltil::ADMIN .  '/News/update/default.html?id=' . $newsId;
	}
}